package enemyObject;

import com.sxt.AnimationObj;
import OwnSideObject.BulletObj;
import com.sxt.GameMusic;
import com.sxt.GameWin;

import java.awt.*;

/**
 * 敌方boss
 */
public class BossObj extends EnemyObject{
    static int BOSS_WIDTH = 169; //BOSS的宽度
    static int BOSS_HEIGHT = 258; //BOSS的高度
    //敌方boss爆炸动画效果图片张数
    public static int AnimationNums = 6;
    //boss动画效果
    boolean animation0=true;
    //boss的横向移动速度
    int speedX;
    //boss的初始生命值
    int initialLife = 100;
    //boss状态
    public static boolean isAlive = true;
    public BossObj() {
        super();
    }

    public BossObj(String image, GameWin frame) {
        super(image, frame);
    }

    public BossObj(String image, int x, int y, int speedY, GameWin frame,int flag) {
        super(image, x, y, speedY, frame,flag);
        this.speedX=speedY;
        this.life=initialLife;
        this.score=20;
    }

    @Override
    public void paintSelf(Graphics s) {
        //动画替身
       if (this.flag==2){
           this.Frame.animationObjs.add(new AnimationObj("images/enemy3_down",".png",6,this.x,this.y,this.Frame));
           this.Frame.removeList.add(this);
       }

        if (animation0){
            s.drawImage(image,x,y,null);
            animation0=false;
        }else {
            s.drawImage(Toolkit.getDefaultToolkit().getImage("images/enemy3_n2.png"),x,y,null );
            animation0=true;
        }
        //敌方boss与我方子弹碰撞检测
        if (!this.Frame.bulletObjList.isEmpty()&&this.flag==1)
            for (BulletObj bulletObj:this.Frame.bulletObjList){
                if (this.getRec().intersects(bulletObj.getRec())){
                    this.life--;
                    bulletObj.x=GameWin.MY_BULLET_VANISH_LOCATION_X;
                    bulletObj.y=GameWin.MY_BULLET_VANISH_LOCATION_Y;
                    this.Frame.removeList.add(bulletObj);
                }
            }
        //如果敌方boss血量为0；
        if (this.life<=0){
            GameMusic.enemy3_down.play();
            this.Frame.animationObjs.add(new AnimationObj("images/enemy3_down",".png",6,this.x,this.y,this.Frame));
            this.Frame.removeList.add(this);
            this.Frame.bacGroundObj.score+=this.score;
            if (this.Frame.status==5)
                this.Frame.bossObj=null;
            if (this.Frame.status==1)
                isAlive = false;
        }

        //控制boss运行方向和速度
        if (x>GameWin.WINDOW_WIDTH - BOSS_WIDTH)
            speedX*=-1;
        if (x<0)
            speedX*=-1;
        x+=speedX;

        //画出boss血条
        s.setColor(Color.RED);
        s.drawRect(x, y + 30, BOSS_WIDTH, 10);
        s.fillRect(x, y + 30, (int)((BOSS_WIDTH) * ((double)life / initialLife)), 10);

    }

    @Override
    public Rectangle getRec() {
        return new Rectangle(x,y,BOSS_WIDTH,BOSS_HEIGHT);
    }
    @Override
    public void DeBug() {
        System.out.println("BossObj class");
    }
}
